//using Mono.Cecil;
//using System.Linq;
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using UnityEditor;
//using Mono.Cecil.Cil;
//using Unity.VisualScripting;
//using UnityEngine.ResourceManagement.AsyncOperations;

//public static class TestDllDependency
//{
//    [MenuItem("Test/TestDllDependency")]
//    // Start is called before the first frame update
//    static void Start()
//    {
//        string path = System.IO.Path.GetDirectoryName(Application.dataPath) + "/Library/ScriptAssemblies/UnityEditor.UI.dll";
//        AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(path);
//        foreach (var reference in assembly.MainModule.AssemblyReferences)
//        {
//            Debug.LogError(reference.Name);
//        }
//    }

//    [MenuItem("Test/TestDllDependency2")]
//    static void Main()
//    {
//        string path = System.IO.Path.GetDirectoryName(Application.dataPath) + "/Library/ScriptAssemblies/Assembly-CSharp.dll";
//        //string path = System.IO.Path.GetDirectoryName(Application.dataPath) + "/Library/ScriptAssemblies/cframework.dll";
//        Debug.LogError("test: " + GetDependencyGenericDLL(path).ToCommaSeparatedString());



//    }


//    static List<string> GetDependencyGenericDLL(string dllPath)
//    {
//        var loadedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();

//        DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();

//        // ��������ӡÿ�����򼯵����ƺ�λ��
//        foreach (var ass in loadedAssemblies)
//        {
//            resolver.AddSearchDirectory(System.IO.Path.GetDirectoryName(ass.Location));
//        }



//        ReaderParameters readerParameters = new ReaderParameters
//        {
//            AssemblyResolver = resolver
//        };

//        string path = dllPath;
//        AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(path, readerParameters);

//        HashSet<string> m = new HashSet<string>();

//        foreach (var module in assembly.Modules)
//        {
//            foreach (var type in module.GetTypeReferences())
//            {
//                var t = type.Resolve();

//                if (t.Scope != module)
//                {
//                    bool found = false;
                    
//                    if (t.GenericParameters.Count > 0)
//                    {
//                        if (!t.GenericParameters.All(b => { return b.HasReferenceTypeConstraint || b.Constraints.Count > 0 && b.Constraints.All(c => { var a = c.Resolve(); return a.IsClass; }); }))
//                        {
//                            //Debug.LogError($"method: {t.FullName} {t.GenericParameters.Count} ({t.Scope.Name})");
//                            found = true;
//                        }
//                    }

//                    if (!found)
//                    {
//                        foreach (var me in t.Methods)
//                        {
//                            if (me.GenericParameters.Count > 0)
//                            {
//                                if (!me.GenericParameters.All(b => b.HasReferenceTypeConstraint || b.Constraints.Count > 0 && b.Constraints.All(b => { var a = b.Resolve();  return a.IsClass; })))
//                                {
//                                    Debug.LogError($"method: {me.FullName} {me.GenericParameters.Count} ({t.Scope.Name})");

//                                    found = true;
//                                    break;
//                                }
//                            }
//                        }
//                    }

//                    if (found)
//                    {
//                        m.Add(t.Scope.Name);
//                    }
//                }
//            }
//        }


//        assembly.Dispose();

//        return m.ToList();

//    }
//}
